﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FluentData;
using Framework.Data;

namespace Framework.Core
{
    /// <summary>
    /// 酒店单位
    /// </summary>
    [Serializable]
    public class HotelOrg
    {
        #region 常规字段

        /// <summary>
        /// 酒店单位唯一标识
        /// </summary>
        public string HotelOrgId { get; set; }

        /// <summary>
        /// 酒店单位名称
        /// </summary>
        public string HotelOrgName { get; set; }

        /// <summary>
        /// 酒店类型
        /// </summary>
        public OrgType OrgType { get; set; }

        /// <summary>
        /// 酒店品牌
        /// </summary>
        public HotelLevel HotelLevel { get; set; }

        /// <summary>
        /// 酒店物业类型
        /// </summary>
        public HotelPropertyType PropertyType { get; set; }

        /// <summary>
        /// 酒店业务范围
        /// </summary>
        public HotelBizScopeType BizScopeType { get; set; }

        /// <summary>
        /// 区号，对应Area_Info里的地区区号
        /// </summary>
        public string AreaId { get; set; }

        /// <summary>
        /// 开业时间
        /// </summary>
        public DateTime? OpenDate { get; set; }

        /// <summary>
        /// 地址
        /// </summary>
        public string Address { get; set; }

        /// <summary>
        /// 联络电话
        /// </summary>
        public string Telephone { get; set; }

        /// <summary>
        /// 传真
        /// </summary>
        public string Fax { get; set; }

        /// <summary>
        /// 邮编
        /// </summary>
        public string ZipCode { get; set; }

        #endregion

        public HotelOrg()
        {
        }

        //TODO: 将所有酒店信息放入缓存
        /// <summary>
        /// 加载所有酒店
        /// </summary>
        /// <returns></returns>
        public static List<HotelOrg> Load()
        {
            string sql = "SELECT sOrgID,sParentOrgID,sOrgName,sOrgTypeID,sHotelLevel,sHotelProperty,sHotelBiz,sAreaID,dOpenDate,sAddress,sTel,sFax,sZip FROM Org_Info WHERE bIsDel=0";

            using (var context = DataHelper.GetBaseDbContext())
            {
                var hotels = context.Sql(sql).QueryMany<HotelOrg>(delegate(HotelOrg hotel, IDataReader row)
                    {
                        hotel.HotelOrgId = row.GetString("sOrgID");
                        hotel.HotelOrgName = row.GetString("sOrgName");
                        // TODO: 更多字段
                    });

                return hotels;
            }
        }

        #region GetAllRooms

        //TODO: 酒店里所有房间存入缓存
        /// <summary>
        /// 获取酒店里所有的房间
        /// </summary>
        /// <returns></returns>
        public List<Room> GetAllRooms()
        {
            string sql = " SELECT sHotelID,sHall,sFloor,sRoomNo,sRoomTypeID FROM Room_Info WHERE bIsDel=0 AND sHotelID=@0";

            using (var context = DataHelper.GetBaseDbContext())
            {
                var rooms = context.Sql(sql, HotelOrgId).QueryMany<Room>(delegate(Room room, IDataReader row)
                    {
                        room.Hotel = this;
                        //room.Hall =;
                        //room.Floor =;
                        room.RoomNo = row.GetString("sRoomNo");
                        room.RoomType = RoomType.Load().Find(s => s.RoomTypeCode == row.GetString("sRoomTypeID"));
                        //TODO: 更多字段
                    });

                return rooms;
            }
        }

        #endregion
    }
}
